import React, { Component } from 'react'
import axios from 'axios'
import './index.css'
export default class Login extends Component {
    state  = {
        username:'',
        password:''
    }
    render() {
        return (
            <div className="login-container">
                
               <div className="login-box">
                   <div className="touxiang">
                       <img src='https://img.chuangbie.com/user/icon/default.jpg' alt="" />
                   </div>
                   {/* action="../../api/login.php" */}
                    <form action="../../api/login.php" className="login-form">
                            <input type="text"  placeholder="请输入用户名"  ref="UserName" />
                            <input type="password"  placeholder="请输入密码"  ref="PassWord" />
                        <button className="" onClick={this.login}>登录</button>
                    </form>
               </div>
            </div>
        )
    }

    componentDidMount(){
       
    }
    login = (e) =>{
        e.preventDefault();
            console.log(this.refs.UserName.value,this.refs.PassWord.value);
                axios({
                    method:'POST',
                    url:'../../api/login.php',
                    data: {
                        username:this.refs.UserName.value,
                        password: this.refs.PassWord.value
                    },   
                }).then(res =>{
                    res = JSON.parse(res);
                    if(res.code == 1){
                        // setCookie('login',username.value)
                    }
                })
    }
}
